package kr.hkit.androidcomplete02.ch16;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class DialogFragmentEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		Log.d("DialogFragment", " DialogFragmentEx - onCreate" );
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_dialog);
	}
	
	public void mOnClick(View v){
		DialogFragmentTest dlg = new DialogFragmentTest();
		dlg.show(getFragmentManager(), "Dialog Fragment");
	}
}

class DialogFragmentTest extends DialogFragment{
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Log.d("DialogFragment", " DialogFragmentTest - onCreateDialog" );
		
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("notify")
		.setMessage("Dialog Fragment is opened")
		.setPositiveButton("ok", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(getActivity(), "pressed ok button", 0).show();
				
			}
		})
		.setNegativeButton("close", null);
		
		return builder.create();
	}
	
	
	
}